Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP_Add Django Debug Toolbar #2940

Draft
wants to merge 4 commits into
base: testing
Choose a base branch
from

Conversation

FroggyFlox
Copy link
Member

Initial commit adding Django Debug Toolbar #2939

  • Add django-debug-toolbar package to the optional dev dependency group
  • Add --dev flag to build.sh to run poetry install with that flag
  • Add DjDTB to settings.py
  • Add DjDTB urls

This pull request is created with the only purpose to illustrate what would need to be implemented to use Django Debug Toolbar.
Ideally, all changes to settings.py and urls.py would need to be scripted as well so that no manual configuration would be required.

To run this branch, first checkout, then build from source with the new --dev flag. For instance, I run the following:

cd /opt/rockstor
systemctl stop rockstor rockstor-pre rockstor-build rockstor-bootstrap postgresql && systemctl start postgresql && ./build.sh --dev && poetry run initrock && systemctl enable --now rockstor-bootstrap && poetry run debug-mode ON

Note that DEBUG must be True for the toolbar to show up.

Add django-debug-toolbar package to the optional `dev` dependency group
Add `--dev` flag to build.sh to run `poetry install` with that flag
Add DjDTB to settings.py
Add DjDTB urls
Comment on lines 482 to 487
DEBUG_TOOLBAR_CONFIG = {
# Update to the latest AJAX request
# Without this, we can only catch the initial request
# which is not helpful in most of our cases
"UPDATE_ON_FETCH": True
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DEBUG_TOOLBAR_CONFIG = {
# Update to the latest AJAX request
# Without this, we can only catch the initial request
# which is not helpful in most of our cases
"UPDATE_ON_FETCH": True
}
DEBUG_TOOLBAR_CONFIG = {
# Update to the latest AJAX request
# Without this, we can only catch the initial request
# which is not helpful in most of our cases
"UPDATE_ON_FETCH": True
# If using htmx, to retain toolbar handle
# through page renders add this
"ROOT_TAG_EXTRA_ATTRS": "hx-preserve"
}

If the project is contemplating to use htmx (#2735 and #2821) then this would also be required (among other things of course to enable htmx overall), according to:
https://django-debug-toolbar.readthedocs.io/en/stable/tips.html#working-with-htmx-and-turbo

Rely on the DJANGO_DEBUG env variable to set DEBUG boolean that will in
turn decide the installation of the dev group dependencies (includes
the Django debug toolbar) as the appearance of the toolbar in the UI.

Leave commented (= unset) by default to keep the default build NOT in
the dev mode.
@FroggyFlox
Copy link
Member Author

@phillxnet , I have now tried a different approach to "trigger" the installation of the dev dependencies and the toolbar itself into Django. The idea was to try to "streamline/simplify" the process for the user/developer and cut down the number of steps. I'm anxious about affecting "normal" builds and installs, though, so I would appreciate your feedback; hopefully my commits here won't affect an RPM build, install, and update.

Testing

Ensure all traces from previous/current install are wiped

systemctl stop rockstor rockstor-pre rockstor-build rockstor-bootstrap
rm -vf /usr/lib/systemd/system/rockstor*
systemctl daemon-reload
# DJANGO_DEBUG should not be set but let's make sure of it
unset $DJANGO_DEBUG

cd /opt/rockstor
rm -rf .venv/
rm -rf static/

Now, we can build
Manually edit .env to include DJANGO_DEBUG=True

Given this would be the very first run of the script, we can't rely on
rockstor-build.service to run build.sh with the ENV from .env so we need to set it manually here

systemctl stop postgresql && systemctl start postgresql && DJANGO_DEBUG=True ./build.sh && poetry run initrock && systemctl enable --now rockstor-bootstrap

Open browser and visit Rockstor's IP: the toolbar shows up

To test rebuild after some development edits:

# Wipe existing venv
cd /opt/rockstor
rm -rf .venv/
rm -rf static/
systemctl stop postgresql rockstor rockstor-pre rockstor-build rockstor-bootstrap && systemctl start rockstor-build && systemctl enable --now rockstor-bootstrap

Open browser and visit Rockstor's IP: the toolbar shows up

To test a normal build still works without installing the Debug Toolbar
Manually edit .env to comment DJANGO_DEBUG=True

cd /opt/rockstor
rm -rf .venv/
rm -rf static/
systemctl stop postgresql rockstor rockstor-pre rockstor-build rockstor-bootstrap && systemctl start rockstor-build && systemctl enable --now rockstor-bootstrap

Open browser and visit Rockstor's IP: the toolbar DOES NOT show up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants